define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sub_order/index' + location.search,
                    add_url: 'sub_order/add',
                    edit_url: 'sub_order/edit',
                    del_url: 'sub_order/del',
                    multi_url: 'sub_order/multi',
                    table: 'sub_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'sub_order_sn', title: __('Sub_order_sn')},
                        {field: 'type', title: __('Type'), searchList: {"add_time":__('Type add_time'),"medicine":__('Type medicine')}, formatter: Table.api.formatter.normal},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'add_hours', title: __('add_hours')},
                        {field: 'pay_status', title: __('Pay_status'), searchList: {"0":__('Pay_status 0'),"1":__('Pay_status 1')}, formatter: Table.api.formatter.status},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"trash":__('Trash'),"deleted":__('Deleted')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.id', title: __('Order.id')},
                        {field: 'order.user_id', title: __('Order.user_id')},
                        {field: 'order.patient_id', title: __('Order.patient_id')},
                        {field: 'order.service_id', title: __('Order.service_id')},
                        {field: 'order.service_basic_id', title: __('Order.service_basic_id')},
                        {field: 'order.hospital_id', title: __('Order.hospital_id')},
                        {field: 'order.department_id', title: __('Order.department_id')},
                        {field: 'order.document_type', title: __('Order.document_type')},
                        {field: 'order.begin_time', title: __('Order.begin_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.note', title: __('Order.note')},
                        {field: 'order.start_address', title: __('Order.start_address')},
                        {field: 'order.end_address', title: __('Order.end_address')},
                        {field: 'order.medicine_type', title: __('Order.medicine_type')},
                        {field: 'order.prescription_img', title: __('Order.prescription_img')},
                        {field: 'order.express', title: __('Order.express')},
                        {field: 'order.express_no', title: __('Order.express_no')},
                        {field: 'order.express_time', title: __('Order.express_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.create_time', title: __('Order.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.accept_time', title: __('Order.accept_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.start_time', title: __('Order.start_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.end_time', title: __('Order.end_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.add_time', title: __('Order.add_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.bed_no', title: __('Order.bed_no')},
                        {field: 'order.self_care_ability', title: __('Order.self_care_ability')},
                        {field: 'order.finish_time', title: __('Order.finish_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.status', title: __('Order.status')},
                        {field: 'order.patient_commented', title: __('Order.patient_commented')},
                        {field: 'order.worker_commented', title: __('Order.worker_commented')},
                        {field: 'order.coupon_id', title: __('Order.coupon_id')},
                        {field: 'order.coupon_money', title: __('Order.coupon_money'), operate:'BETWEEN'},
                        {field: 'order.total_price', title: __('Order.total_price'), operate:'BETWEEN'},
                        {field: 'order.pay_price', title: __('Order.pay_price'), operate:'BETWEEN'},
                        {field: 'order.pay_time', title: __('Order.pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.platform_money', title: __('Order.platform_money'), operate:'BETWEEN'},
                        {field: 'order.worker_money', title: __('Order.worker_money'), operate:'BETWEEN'},
                        {field: 'order.medicine_price', title: __('Order.medicine_price'), operate:'BETWEEN'},
                        {field: 'order.refund_status', title: __('Order.refund_status'), formatter: Table.api.formatter.status},
                        {field: 'order.refund_money', title: __('Order.refund_money'), operate:'BETWEEN'},
                        {field: 'order.refund_time', title: __('Order.refund_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order.refund_msg', title: __('Order.refund_msg')},
                        {field: 'order.transfer_arr', title: __('Order.transfer_arr')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});